package com.miaoquan.mqapitbk.config;

import com.miaoquan.mqapitbk.config.properties.TbkProperties;
import com.miaoquan.mqapitbk.utils.TbkUtil;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * 淘宝客配置
 *
 * @author Fa
 * @date 2020-03-29 19:03
 */
@Configuration
@EnableConfigurationProperties(TbkProperties.class)
@Import({TbkUtil.class})
public class TbkConfig {

    /**
     * 淘宝客配置属性
     */
    private final TbkProperties tbkProperties;

    public TbkConfig(TbkProperties tbkProperties) {
        this.tbkProperties = tbkProperties;
    }

    @Bean
    public TaobaoClient taobaoClient() {
        return new DefaultTaobaoClient(
                tbkProperties.getUrl(),
                tbkProperties.getAppCert().getAppKey(),
                tbkProperties.getAppCert().getAppSecret()
        );
    }


}
